package com.fuze.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuze.domain.dto.ContractQueryDTO;
import com.fuze.domain.dto.DataGridView;
import com.fuze.domain.dto.GuaranteedShareContractDTO;
import com.fuze.domain.model.GuaranteedShareContract;
import com.fuze.mapper.GuaranteedShareContractMapper;
import com.fuze.service.GuaranteedShareContractService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @author sepc_
 * @date 5/19/2021 15:00
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class GuaranteedShareContractServiceImpl implements GuaranteedShareContractService {

    final GuaranteedShareContractMapper guaranteedShareContractMapper;

    @Override
    public DataGridView queryByType(ContractQueryDTO queryDTO) {
        Page<GuaranteedShareContract> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
        this.guaranteedShareContractMapper.selectPage(page, null);
        return new DataGridView(page.getTotal(), page.getRecords());
    }

    @Override
    public GuaranteedShareContract findById(Integer id) {
        return this.guaranteedShareContractMapper.selectById(id);
    }

    @Override
    public int add(GuaranteedShareContractDTO guaranteedShareContractDTO) {
        GuaranteedShareContract contract = new GuaranteedShareContract();
        BeanUtils.copyProperties(guaranteedShareContractDTO, contract);
        return this.guaranteedShareContractMapper.insert(contract);
    }

    @Override
    public int update(GuaranteedShareContractDTO guaranteedShareContractDTO) {
        GuaranteedShareContract contract = new GuaranteedShareContract();
        BeanUtils.copyProperties(guaranteedShareContractDTO, contract);
        return this.guaranteedShareContractMapper.updateById(contract);
    }

    @Override
    public int delete(Integer[] ids) {
        return this.guaranteedShareContractMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
